var prize={
		normal:0,
		third:0,
		second:0,
		first:0,
		grand:0
}
$("#normal").click(function(){
	$("div.prize").attr("disabled",true);
	if(prize.third == 0 && prize.second == 0 && prize.first == 0 && prize.grand == 0){
		$("div.prize-number").html("");
		$("#normal").attr("src","img/normalprizeOn.png");
		prize.normal=1;
		var i=0,
		st=setTimeout(function(){
			start();	
			i++
		})
		var si=setInterval(function(){
			if(i<=49){
				start()
			}
			i++;
		},8500)
	}
	prize.normal = 0;
	
});
$("#third").click(function(){
	if(prize.normal == 0 && prize.second == 0 && prize.first == 0 && prize.grand == 0){
		$("div.prize-number").html("");
		$("#third").attr("src","img/thirdprizeOn.png");
		prize.third=1;
		var i=0,
		st=setTimeout(function(){
			start();	
			i++;
		})
		var si=setInterval(function(){
			if(i<=24){
				start()
			}
			i++;
		},8500)
	}
	prize.third = 0;
});
$("#second").click(function(){
	if(prize.normal == 0 && prize.third == 0 && prize.first == 0 && prize.grand == 0){
		$("div.prize-number").html("");
		$("#second").attr("src","img/secondprizeOn.png");
		prize.second=1;
		var i=0,
		st=setTimeout(function(){
			start();	
			i++;
		})
		var si=setInterval(function(){
			if(i<=9){	
				start()
			}
			i++;
		},8500)
		prize.second=0;
	}
});
$("#first").click(function(){
	if(prize.normal == 0 && prize.third == 0 && prize.second == 0 && prize.grand == 0){
		$("div.prize-number").html("");
		
		prize.first=1;
		var i=0,
		st=setTimeout(function(){
			start();	
			i++;
		})
		var si=setInterval(function(){
			if(i<=2){
				start()
			}
			i++;
		},8500)
		prize.frist=0;
	}
});
$("#grand").click(function(){
	if(prize.normal == 0 && prize.third == 0 && prize.first == 0 && prize.second == 0){
		$("div.prize-number").html("");
		prize.grand=1;
		var i=0;
		start();	
		prize.grand = 0;
	}
});
function start(){
	var q=0,b=0,s=0,g=0,number="";
	var timer1=setInterval(function(){
		q++;
		if(q == 4){
			clearInterval(timer1);
		}
		var n=parseInt(1+Math.random()*3);
		$("#thousand").text(n)
	},500)
	var timer2=setInterval(function(){
		b++;
		if(b == 8){
			clearInterval(timer2);
		}
		var n=parseInt(Math.random()*3);
		$("#hundred").text(n)
	},500)
	var timer3=setInterval(function(){
		s++;
		if(s == 12){
			clearInterval(timer3);
		}
		var n=parseInt(Math.random()*10);
		$("#ten").text(n)
	},500)
	var timer4=setInterval(function(){
		g++;
		if(g == 16) {
			clearInterval(timer4);
			number=$("#thousand").text()+$("#hundred").text()+$("#ten").text()+$("#digit").text();
			$("div.prize-number").append("<span class='normal'>"+number+"</span>");
		}
		if(g<16){
			
		var n=parseInt(Math.random()*10);
		$("#digit").text(n)
		}
	},500)
	
}